import processing.serial.*;
Serial myPort;
String val;
int next;
float voltage, pressure, airflow, airvolume, current_time, time_of_event;
void setup() {
  size(200, 200);
  myPort = new Serial(this, Serial.list()[0], 115200);
  myPort.bufferUntil('\n');
}
void draw() {
  //we can leave the draw method empty, 
  //because all our programming happens in the serialEvent (see below)
  
}
void serialEvent(Serial myPort) {
  val = myPort.readStringUntil('\n');
  if (val != null) {
    if (val.equals("voltage : ")) {
      next = 1;
      return;
    }
    if (val.equals("pressure : ")) {
      next = 2;
      return;
    }    
    if (val.equals("airflow : ")) {
      next = 3;
      return;
    }
    if (val.equals("air volume : ")) {
      next = 4;
      return;
    }
    if (val.equals("current time : ")) {
      next = 5;
      return;
    }
    if (val.equals("time_of_event : ")) {
      next = 6;
      return;
    }
    
    switch (next) {
    case 1 :
      println("voltage : " + val);
      voltage = Float.parseFloat(val); 
      next = 0;
      break;
    case 2 :
      println("pressure : " + val);
      pressure = Float.parseFloat(val); 
      next = 0; 
      break;
    case 3 :
      println("airflow : " + val);
      airflow = Float.parseFloat(val); 
      next = 0;
      break;
    case 4 :
      println("air volume : " + val);
      air_volume = Float.parseFloat(val); 
      next = 0;
      break;
    case 5 :
      println("current time : " + val);
      current_time = Float.parseFloat(val); 
      next = 0;
      break;
    case 6 :
      println("time of event : " + val);
      time_of_event = Float.parseFloat(val); 
      next = 0;
      break;
    }
  }
}
